package com.lxd.property.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lxd.property.pojo.Shacconumber;
import com.lxd.property.service.ShacconumberService;
import com.lxd.property.utils.Page;

@Controller
@RequestMapping("shacconumber")
public class ShacconumberController {

	@Autowired
	private ShacconumberService shacconumberService;

	@RequestMapping(value = "findAllShacconumber", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> findAllShacconumber(Page util,
			@RequestParam(value = "s_name", required = false) String s_name) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("start", util.getStart());
		map.put("rows", util.getRows());
		map.put("s_name", s_name);
		List<Shacconumber> list = shacconumberService.findAllShacconumber(map);
		Long total = shacconumberService.findAllShacconumberCount(map);

		Map<String, Object> con = new HashMap<String, Object>();

		con.put("total", total);
		con.put("rows", list);
		return con;

	}

	@RequestMapping(value = "addShacconumber", method = RequestMethod.POST)
	@ResponseBody
	public boolean addShacconumber(Shacconumber shacconumber) {
		int i = shacconumberService.addShacconumber(shacconumber);
		return i == 1;

	}

	@RequestMapping(value = "findShacconumberById", method = RequestMethod.POST)
	@ResponseBody
	public Shacconumber findShacconumberById(Integer id) {
		return shacconumberService.findShacconumberById(id);

	}

	@RequestMapping(value = "updateShacconumber", method = RequestMethod.POST)
	@ResponseBody
	public boolean updateShacconumber(Shacconumber shacconumber) {
		return shacconumberService.updateShacconumber(shacconumber) == 1;
	}

	@RequestMapping(value = "updateStateShacconumberById", method = RequestMethod.POST)
	@ResponseBody
	public boolean updateStateShacconumberById(@RequestParam(value = "id", required = false) Integer id,
			@RequestParam(value = "state", required = false) Integer state) {
		Map<String,Object> map=new HashMap<String, Object>();
		state=state==0?1:0;
		map.put("id", id);
		map.put("state", state);
		System.out.println(">>>>>>>>>>>>>"+id);
		System.out.println(">>>>>>>>>>>>》"+state);
		return shacconumberService.updateStateShacconumberById(map) == 1;
	}

	@RequestMapping(value = "findShacconumberByName", method = RequestMethod.POST)
	@ResponseBody
	public boolean findShacconumberByName(String aliasname) {
		return shacconumberService.findShacconumberByName(aliasname) == null;

	}

	@RequestMapping(value = "findShacconumberByNameToCompare", method = RequestMethod.POST)
	@ResponseBody
	public boolean findShacconumberByNameToCompare(Shacconumber shacconumber) {
		if (shacconumberService.findShacconumberByNameToCompare(shacconumber) == null) {
			return true;
		} else if (shacconumber.getId().equals(
				shacconumberService.findShacconumberByNameToCompare(
						shacconumber).getId())) {
			return true;
		} else {
			return false;
		}
	}

}
